package bg.ittalents.homework.airport;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

public class FileReader implements Reader {

	private File inputFile;
	private ArrayList<String> events;
	private Iterator<String> eventIterator;

	public FileReader(String fileName) throws FileNotFoundException {

		inputFile = new File(fileName);
		events = new ArrayList<String>();
		readEvents();
		eventIterator = events.iterator();

	}

	private void readEvents() throws FileNotFoundException {

		Scanner cin = new Scanner(inputFile);

		while (cin.hasNextLine()) {
			events.add(cin.nextLine());
		}

		cin.close();
	}

	@Override
	public boolean hasNextEvent() {
		return eventIterator.hasNext();
	}

	@Override
	public String getNextEvent() {
		if (eventIterator.hasNext()) {
			return eventIterator.next();
		}
		return null;
	}

}
